package com.yanqu.road.server.manger;

import com.yanqu.road.entity.servercenter.MallRebate;
import com.yanqu.road.logic.bussiness.servercenter.ServerBussiness;
import com.yanqu.road.server.TempMgr;
import com.yanqu.road.server.manger.plugin.ManagerReloadListener;
import com.yanqu.road.utils.ConfigHelper;

import java.util.HashMap;
import java.util.Map;

public class MallRebateMgr extends TempMgr {
    private static Map<Integer, MallRebate> mallRebateMap = new HashMap<>();
    private static ManagerReloadListener managerReloadListener;
    @Override
    public boolean init() throws Exception {
        return reload();
    }

    @Override
    public boolean reloadConfig() throws Exception {
        int channelId = ServerListMgr.getChannelId(ConfigHelper.getLong("serverId"));
        mallRebateMap = ServerBussiness.getMallRebateMap(channelId);
        notifyReload();
        return true;
    }

    @Override
    public boolean reloadData() throws Exception {
        return true;
    }

    @Override
    public boolean stop() {
        return false;
    }

    public static Map<Integer, MallRebate> getMallRebateMap() {
        return new HashMap<>(mallRebateMap);
    }

    public static void addReloadListener(ManagerReloadListener reloadListener) {
        managerReloadListener = reloadListener;
    }

    private static void notifyReload() {
        if (null != managerReloadListener) {
            managerReloadListener.notifyReload();
        }
    }
}
